
#include "exercise_radar_car.h"
#include <stdint.h>
#include <stdio.h>
#include <string.h>

#include "exercise_radar_car.h"

#include "gd32f4xx.h"
#include "systick.h"
#include <stdio.h>
#include <stdint.h>
#include "gpio_buzzer.h"

#include <string.h>
#include "key.h"
#include "yudie.h"
#include "matrix_button.h"
#include "yudie.h"
#include <stdlib.h>
//
#include "led_driver.h"
#include "wkup_driver.h"
#include "single_btn_driver.h"
#include "buzzer_driver.h"
#include "matrix_btn_driver.h"
#include "usart0_driver.h"
#include "usart1_driver.h"
#include "exti0_driver.h"
#include "exti1_driver.h"
#include "hr_sc04_driver.h"
#include "nixie_driver.h"
#include "nixie.h"
#include "timer5_driver.h"
#include "pwm_driver.h"
#include "timer1_buzzer.h"
#include "timer0_driver.h"
#include "dma1_usart0_rx_driver.h"
#include "rtc_driver.h"
#include "free_watchdog_driver.h"
#include "exercise_i2c_pcf8563.h"
#include "tetris.h"

#include "adc_multi_channel_dma.h"
#include "adc_adc1_in1_ntc.h"
#include "spi_soft_oled.h"
#include "spi_hard_oled.h"
#include "adc_dianweiqi.h"
#include "exercisee_spi_dianweiqi.h"
#include "pmu_driver.h"

//
static uint8_t received_data[1024] = {0};

void clear_received_data()
{
    int len = sizeof(received_data);
    int i;
    for (i = 0; i < len; i++)
    {
        received_data[i] = '\0'; // 或 str[i] = 0;
    }
}

void onReceiveData(uint8_t *data, uint16_t len)
{
    printf("main receive %s,data[0]=%d,len:%d\n", (char *)data, data[0], len);
    clear_received_data();
    strcpy((char *)received_data, (char *)data);
    //
    //pmu_driver_sleepmode(data[0]);//这里又问题,不能在中断内进入睡眠模式,否则会一直卡在中断中,接手不到其他中断
}

// PB2闪灯
void led_config(void)
{
    rcu_periph_clock_enable(RCU_GPIOB);
    gpio_mode_set(GPIOB, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO_PIN_2);
    gpio_output_options_set(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_25MHZ, GPIO_PIN_2);
}

void toggle_led()
{
    gpio_bit_toggle(GPIOB, GPIO_PIN_2);
}

void my_delay_ms(uint32_t count)
{
    uint32_t delay = count * 42200;
    while (delay--)
        ;
}

int main(void)
{
    //systick_config();
    usart0_driver_tx_config();
    usart0_driver_rx_config();

    led_config();

    // exercise_radar_main();

    // pwm_driver_test();

    // buzzer_timer_test();

    // timer0_driver_test();
    // dma1_usart0_rx_test();

    // rtc_driver_test();
    // printf("重启了\n");
    // free_watchdog_test();

    // exercise_i2c_pcf8563_test();

    // tetris_launch();

    // adc_multi_channel_dma_test();
    // adc_adc1_in1_ntc_test();
    // OLED_Init_ISP();

    //    while (1)
    //    {
    //			printf("start...\n");
    //        OLED_ShowString_ISP(0, 0, "Hello", 8, 1); // 6*8 “ABC”
    //        //OLED_ShowNum_ISP(0,0,12,4,8,1);
    //        OLED_Refresh_ISP();
    //        delay_1ms(1000);
    //    }

    // exercisee_spi_dianweiqi_test();
    //pmu_driver_test();

    while (1)
    {
        // 反转GPIO状态，当前是1则变0，当前是0则变1
        toggle_led();

        my_delay_ms(1000);

        //delay_1ms(1000);
    }
}
